local AnimateHelper

AnimateHelper = function(path, fileName, delay, loops)
    -- 从 plist 文件加载精灵帧
    local sfc = cc.SpriteFrameCache:getInstance()
    sfc:addSpriteFrames(path .. fileName .. ".plist", path .. fileName .. ".pvr.ccz")

    -- 创建动画
    local animation = cc.Animation:create()
    animation:setDelayPerUnit(delay or 0.2)
    animation:setLoops(loops or 65535)

    -- 获取第一帧
    local frame = sfc:getSpriteFrameByName(fileName .. ".png")
    animation:addSpriteFrame(frame)

    -- 使用第一帧创建精灵
    local sprite = cc.Sprite:createWithSpriteFrame(frame)

    -- 获取剩下的精灵帧
    local i = 2
    while true do
        frame = sfc:getSpriteFrameByName(fileName .. i .. ".png")
        if frame == nil then
            break
        end
        animation:addSpriteFrame(frame)
        i = i + 1
    end

    local animate = cc.Animate:create(animation)

    return sprite, animate
end

return AnimateHelper
